<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function intersection (nums1, nums2) {
      
      let nums3 = []
   for(let i = 0; i<nums1.length; i++) {
    for(let j = 0; j<nums2.length; j++) {
      if(nums1[i] == nums2[j]) {
        nums3.push(nums1[i])
        nums1.splice(i, 1)
        nums2.splice(j, 1)
        i--
        j--
      }
    }
   }
   const nums4 = nums3.filter((item,index,array) => {
    return array.indexOf(item) === index
   })
   console.log(nums4);

}
let nums1 = [1,2,2,1]
   let nums2 = [2,2]
intersection(nums1,nums2)

  


  </script>
</body>
</html>